home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / ss24x.asm < prev    next >
Assembly Source File  |  1994-02-22  |  15KB  |  405 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file SS24X.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1993 John Horigan, 870 E. El Camino Real #161, Mtn View, CA 94040
  7. ; Copyright (C) 1993 David Max, 185 West End Ave #3H, New York, NY 10023
  8. ;
  9. ; This file is distributed under the terms listed in the document
  10. ; "copying.dj", available from DJ Delorie at the address above.
  11. ; A copy of "copying.dj" should accompany this file; if not, a copy
  12. ; should be available from where this file was obtained.  This file
  13. ; may not be distributed without a verbatim copy of "copying.dj".
  14. ;
  15. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  16. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. ;--------------------------------------------------------------------------
  18. ;
  19. ; Added the Mode X support 96/29/93 - Hartmut Schirmer
  20. ; Reviewed code for 8086 compatibility (Turbo-C GRX) 07/07/93 Hartmut Schirmer
  21. ;
  22.  
  23.     .386
  24. include grdriver.inc
  25. cseg    segment byte public use16 'code'
  26.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  27.  
  28. req_T28         equ    0        ; enable  80x28x16 text mode
  29. req_T50         equ    0        ; enable  80x50x16 text mode
  30. req_3516        equ    0        ; enable  720x350x16 graphics mode
  31. req_4816        equ    0        ; enable  720x480x16 graphics mode
  32. req_lowX        equ    0        ; enable  320x240/320x400/360x480 256 color modes
  33. req_hiX         equ    0        ; disable high resolution mode X support
  34.  
  35. ;--------------------------------------------------------------------------
  36. ; DRIVER HEADER
  37. ;  The following entries MUST match the structure and constant
  38. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  39. ;  The mode word should contain the following bitfields:
  40. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  41. ;     - the adapter type field should be specified
  42. ;     - the memory size field should be specified
  43. ;     - the paging mode field should be specified
  44. ;  The mode set routine will OR in the plane bitfield as it will
  45. ;  change when different color number modes are requested.
  46. ;--------------------------------------------------------------------------
  47.  
  48.     dw      offset mode_set_routine
  49.     dw      offset paging_routine
  50. mode_W  dw      GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  51. ;
  52. ; The 'def_xx' fields are filled in by go32 from the corresponding
  53. ; fields of the 'GO32' environment variable
  54. ;
  55. def_tw  dw      80              ; text width
  56. def_th  dw      25              ; text height
  57. def_gw  dw      640             ; graphics width
  58. def_gh  dw      480             ; graphics height
  59. def_nc  dw      16              ; graphics colors
  60.     dw      offset driver_init_routine
  61.     dw      offset text_mode_table
  62.     dw      offset graphics_mode_table
  63.  
  64. ;
  65. ; Biggest text and graphics sizes
  66. ;
  67. Max_TW  equ     132
  68. Max_TH  equ     50
  69. Max_GWn equ    1024        ; non interlaced!!!
  70. Max_GHn equ    768
  71. Max_GW  equ     1280            ; may be interlaced
  72. Max_GH  equ     1024
  73.  
  74.  
  75. ;--------------------------------------------------------------------------
  76. ; TABLE OF SUPPORTED TEXT MODES
  77. ;       - keep sorted by size
  78. ;       - end with an all 0 entry
  79. ;       - BIOS field = 0xff disables it
  80. ;       - fields:
  81. ;               width,  height, colors, BIOS#+  setup_procedure_index*256
  82. ;--------------------------------------------------------------------------
  83. text_mode_table         label word
  84.     dw      80,     25,     2,      007h +  00000h
  85.     dw      40,     25,     16,     001h +  00000h
  86.     dw      80,     25,     16,     003h +  00000h
  87.     if req_T28
  88.     dw      80,     28,     16,     003h +  val_T28
  89.     endif
  90.     dw      80,     34,     16,     041h +  00000h
  91.     dw      80,     43,     16,     067h +  00000h
  92.     dw      80,     50,     16,     066h +  00000h
  93.     dw      132,    25,     16,     055h +  00000h
  94.     dw      132,    28,     16,     047h +  00000h
  95.     dw      132,    43,     16,     054h +  00000h
  96.     dw      132,    44,     16,     021h +  00000h
  97.     if req_T50
  98.     dw      132,    50,     16,     055h +  val_T50
  99.     endif
  100.     dw    132,     50,     16,    069h +  00000h
  101.     dw      0,      0,      0,      000h +  00000h
  102.  
  103.  
  104. ;--------------------------------------------------------------------------
  105. ; TABLE OF SUPPORTED GRAPHICS MODES
  106. ;       - keep sorted first by colors then by size
  107. ;       - end with an all 0 entry
  108. ;       - BIOS field = 0xff disables it
  109. ;       - fields:
  110. ;               width,  height, colors, BIOS#+  setup_procedure_index*256
  111. ;--------------------------------------------------------------------------
  112. graphics_mode_table     label word
  113.     dw      320,    200,    16,     00dh +  00000h
  114.     dw      640,    200,    16,     00eh +  00000h
  115.     dw      640,    350,    16,     010h +  00000h
  116.     dw      640,    480,    16,     012h +  00000h
  117.     if req_3516
  118.     dw      720,    350,    16,     val_3516        ; Tweaked 16 color mode
  119.     endif
  120.     if req_4816
  121.     dw      720,    480,    16,     val_4816        ; Tweaked 16 color mode
  122.     endif
  123.     dw      800,    600,    16,     058h +  00000h
  124.     dw      1024,   768,    16,     05dh +  00000h
  125.     dw    1280,    960,    16,    06ch +  00000h
  126.     dw      1280,   1024,   16,     064h +  00000h
  127.     dw      320,    200,    256,    013h +  00000h
  128.     if req_lowX
  129.     dw      320,    240,    256,    val_lowXa       ; Mode X      (<64k)
  130.     dw      320,    400,    256,    val_lowXb       ; Mode X      (<64k)
  131.     dw      360,    480,    256,    val_lowXc       ; Mode X      (<64k)
  132.     endif
  133.     dw      640,    400,    256,    05eh +  00000h
  134.     dw      640,    480,    256,    05fh +  00000h
  135.     dw      800,    600,    256,    05ch +  00000h
  136.     dw      1024,   768,    256,    060h +  00000h
  137.     dw    640,    480,    32768,    062h +  00000h
  138.     dw    800,    600,    32768,    063h +  00000h
  139.     dw      0,      0,      0,      000h +  00000h
  140.  
  141.  
  142. ;--------------------------------------------------------------------------
  143. ; TABLE OF SPECIAL SETUP PROCEDURES
  144. ;  You may need such procedures for:
  145. ;     -- reloading fonts on standard EGA or VGA for
  146. ;        higher resolution text modes
  147. ;     -- enable HiColor mode of some Super VGAs
  148. ;     -- Handle the parameter passing conventions of the VESA BIOS
  149. ;     -- put VGA into 256 color plane mode ("MODE X")
  150. ;     -- etc...
  151. ;  There should be one entry in the table for every non-zero
  152. ;  'setup_procedure_index' in the text and graphics mode tables.
  153. ;  The first entry in the table belongs to index 100h, and so on.
  154. ;  The special setup procedure is invoked via a near call.
  155. ;
  156. ;  Entry: DI=address of the mode record from the text or graphics
  157. ;         table to set up.
  158. ;
  159. ;  Exit:  Adapter configured
  160. ;         BX=driver mode word as it should be returned by the mode set
  161. ;            routine. Typically it involves picking up the mode word
  162. ;            from the header and OR-ing in the appropriate bitplane mode
  163. ;            bitfield. (This is not needed for text modes)
  164. ;         AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  165. ;
  166. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  167. ;--------------------------------------------------------------------------
  168. special_setup_table     label word
  169. ;    include vgaext.inc      ; load VGA non BIOS modes
  170.  
  171.  
  172. ;--------------------------------------------------------------------------
  173. ; DRIVER INIT ROUTINE
  174. ;  called once after the driver is loaded
  175. ;  may do one or more of the followings:
  176. ;    - check for proper board type
  177. ;    - check amount of RAM on board, and:
  178. ;       -- update word in header to reflect correct amount
  179. ;       -- disable modes in the tables for which there is not enough RAM
  180. ;    - check for special equipment (HiColor DAC, etc...)
  181. ;
  182. ;  Entry: nothing
  183. ;
  184. ;  Exit:  AX=status:
  185. ;          non-zero: OK,
  186. ;          0: something went wrong (e.g. wrong adapter, etc..)
  187. ;         BX,CX,DX may be trashed
  188. ;
  189. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  190. ;--------------------------------------------------------------------------
  191. driver_init_routine     proc    far
  192.     mov     dx,03ceh
  193.     mov     ax,0e0bh
  194.     out     dx,ax                   ; enable second bank register
  195.     mov     dx,03c5h
  196.     mov     ax,0ff11h               ; set bank registers for R/W banking
  197.     out     dx,ax                   ;  at B000:0000 - B000:FFFF
  198.     ret
  199. driver_init_routine     endp
  200.  
  201.  
  202. ;--------------------------------------------------------------------------
  203. ; MODE SET ROUTINE
  204. ;  sets up a text or graphics mode as close as possible to the one
  205. ;  reguested by the user with regard to number of colors and size.
  206. ;
  207. ;  Entry: AX=mode selection
  208. ;     0 = 80x25 text
  209. ;     1 = default text
  210. ;     2 = text CX cols by DX rows
  211. ;     3 = biggest text
  212. ;     4 = 320x200 graphics
  213. ;     5 = default graphics
  214. ;     6 = graphics CX width by DX height
  215. ;     7 = biggest non-interlaced graphics
  216. ;     8 = biggest graphics
  217. ;     9 = graphics BX colors, CX width by DX height
  218. ;
  219. ;  Exit: BX=driver mode flag
  220. ;        CX=width (in pixels or characters)
  221. ;        DX=height
  222. ;
  223. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  224. ;        YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  225. ;        MUCH TABLE DRIVEN
  226. ;--------------------------------------------------------------------------
  227. mode_set_routine        proc    far
  228.     push    ds
  229.     push    di
  230.     push    si
  231.     mov     si,cs
  232.     mov     ds,si
  233.     cmp     ax,9
  234.     jbe     DoIt
  235.     jmp     Exit
  236. DoIt:   add     ax,ax
  237.     mov     si,ax
  238.     jmp     WORD PTR mode_set_table[si]
  239. mode_set_table  label   word
  240.     dw      offset mode_0
  241.     dw      offset mode_1
  242.     dw      offset mode_2
  243.     dw      offset mode_3
  244.     dw      offset mode_4
  245.     dw      offset mode_5
  246.     dw      offset mode_6
  247.     dw      offset mode_7
  248.     dw      offset mode_8
  249.     dw      offset mode_9
  250. mode_0: mov     si,offset text_mode_table       ; 80x25 text
  251.     mov     bx,def_nc
  252.     mov     cx,80
  253.     mov     dx,25
  254.     jmp     Lookup
  255. mode_1: mov     si,offset text_mode_table       ; default text
  256.     mov     bx,def_nc
  257.     mov     cx,def_tw
  258.     mov     dx,def_th
  259.     jmp     Lookup
  260. mode_2: mov     si,offset text_mode_table       ; CX*DX text
  261.     mov     bx,def_nc
  262.     jmp     Lookup
  263. mode_3: mov     si,offset text_mode_table       ; biggest text
  264.     mov     bx,def_nc
  265.     mov     cx,Max_TW
  266.     mov     dx,Max_TH
  267.     jmp     Lookup
  268. mode_4: mov     si,offset graphics_mode_table   ; 320x200 graphics
  269.     mov     bx,def_nc
  270.     mov     cx,320
  271.     mov     dx,200
  272.     jmp     Lookup
  273. mode_5: mov     si,offset graphics_mode_table   ; default graphics
  274.     mov     bx,def_nc
  275.     mov     cx,def_gw
  276.     mov     dx,def_gh
  277.     jmp     Lookup
  278. mode_6: mov     si,offset graphics_mode_table   ; CX*DX graphics
  279.     mov     bx,def_nc
  280.     jmp     Lookup
  281. mode_7: mov     si,offset graphics_mode_table   ; biggest non-interlaced gr
  282.     mov     bx,def_nc
  283.     mov     cx,Max_GWn
  284.     mov     dx,Max_GHn
  285.     jmp     Lookup
  286. mode_8: mov     si,offset graphics_mode_table   ; biggest graphics
  287.     mov     bx,def_nc
  288.     mov     cx,Max_GW
  289.     mov     dx,Max_GH
  290.     jmp     Lookup
  291. mode_9: mov     si,offset graphics_mode_table   ; CX*DX graphics w/ BX colors
  292. ;
  293. ; At this point:
  294. ;   SI points to the table to search (text or graphics)
  295. ;   BX has colors
  296. ;   CX has width
  297. ;   DX has height
  298. ;
  299. Lookup: xor     ax,ax                           ; last color number seen
  300. Find_C: cmp     [si+4],ax                       ; last color number == this?
  301.     je      Same_C
  302.     jb      Prev_C                          ; end of table -- use last color
  303.     cmp     BYTE PTR [si+6],0ffh            ; valid entry ?
  304.     je      Prev_C                          ; not -- use last color
  305.     mov     ax,[si+4]                       ; record color number
  306.     mov     di,si                           ; start of entries w/ this color
  307.     cmp     ax,bx                           ; enough colors ?
  308.     jae     Find_S
  309. Same_C: add     si,8
  310.     jmp     Find_C
  311. Prev_C: or      ax,ax                           ; found any color at all?
  312.     je      Exit
  313. ;
  314. ; At this point:
  315. ;   DI points into the table to the first entry with the desired color
  316. ;      number (either it has enough colors or it is the highest color
  317. ;      number supported by the driver). Additionally, at least the
  318. ;      first (= smallest size) entry for this color is valid (has a
  319. ;      valid BIOS number).
  320. ;   AX has the color number adjusted for the driver
  321. ;   CX has width
  322. ;   DX has height
  323. ;
  324. Find_S: cmp     [di+4],ax                       ; still the same color #?
  325.     jne     Prev_S
  326.     cmp     BYTE PTR [di+6],0ffh            ; valid entry ?
  327.     je      Prev_S
  328.     cmp     [di],cx
  329.     jb      Next_S
  330.     cmp     [di+2],dx
  331.     jae     GotIt
  332. Next_S: add     di,8
  333.     jmp     Find_S
  334. Prev_S: sub     di,8
  335. ;
  336. ; At this point:
  337. ;   DI points to the table entry we want to set up
  338. ;
  339. GotIt:  mov     ax,[di+6]                       ; BIOS mode number
  340.     or      ah,ah                           ; special ?
  341.     je      doBIOS
  342.     mov     al,ah
  343.     xor     ah,ah
  344.     dec     ax
  345.     add     ax,ax
  346.     mov     si,ax
  347.     call    WORD PTR special_setup_table[si]
  348.     jmp     RetVal
  349. doBIOS: int     10h
  350.     mov     bx,GRD_1_PLANE
  351.     cmp     WORD PTR [di+4],2               ; 2 colors ?
  352.     je      doFLAG
  353.     mov     bx,GRD_4_PLANES
  354.     cmp     WORD PTR [di+4],16              ; 16 colors ?
  355.     je      doFLAG
  356.     mov     bx,GRD_8_PLANES
  357.     cmp     WORD PTR [di+4],256             ; 256 colors ?
  358.     je      doFLAG
  359.     mov     bx,GRD_16_PLANES
  360.     cmp     WORD PTR [di+4],32768           ; 32K colors ?
  361.     je      doFLAG
  362.     mov     bx,GRD_PLANE_MASK               ; something is wrong!!
  363. doFLAG: or      bx,mode_W
  364. RetVal: mov     cx,[di]
  365.     mov     dx,[di+2]
  366. Exit:   pop     si
  367.     pop     di
  368.     pop     ds
  369.     ret
  370. mode_set_routine        endp
  371.  
  372.  
  373. ;--------------------------------------------------------------------------
  374. ; PAGING ROUTINE
  375. ;
  376. ;  Entry: AH=read page
  377. ;         AL=write page
  378. ;
  379. ;  Exit: VGA configured.
  380. ;        AX,BX,CX,DX,SI,DI may be trashed
  381. ;
  382. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  383. ;        This code must be relocatable and may not reference any data!
  384. ;--------------------------------------------------------------------------
  385.     assume  ds:nothing, es:nothing
  386.  
  387. paging_routine  proc    far
  388.     mov     cl,4
  389.     shl     ah,cl ; WD90C3x offset registers have 4k granularity
  390.     shl     al,cl ; => multiply by 16 to get normal VGA 64k bank granularity
  391.     mov     bh,al
  392.     mov     bl,0ah                  ; write bank gets PR0B index code
  393.     mov     al,09h                  ; read bank gets PR0A index code
  394.     mov     dx,03ceh                ; load graphics index register number
  395.     out     dx,ax                   ; set PR0A (read bank)
  396.     mov     ax,bx
  397.     out     dx,ax                   ; set PR0B (write bank)
  398.     ret
  399. paging_routine  endp
  400.  
  401.  
  402. cseg    ends
  403.     end
  404.  
  405.